package com.huxianyang.config;

import com.huxianyang.converter.String2UserConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.convert.support.ConfigurableConversionService;

import javax.annotation.PostConstruct;

/**
 * 
 * @since 2022/06/01 20:09
 * @author HuXianyang
 */
// @Configuration
public class ConverterConfiguration {
    @Autowired
    ConfigurableConversionService conversionService;

    @Autowired
    String2UserConverter string2UserConverter;

    // 利用生命周期函数，给目标组件加点佐料
    @PostConstruct
    public void addConverter() {
        conversionService.addConverter(string2UserConverter);
    }

    // 加完料要记得放回去
    @Bean
    @Primary
    public ConfigurableConversionService conversionService() {
        return conversionService;
    }
}